//
//  Pay&ReceiptView.swift
//  RPay
//
//  Created by Charlie Liao on 2017/7/5.
//  Copyright © 2017年 Charlie. All rights reserved.
//

import UIKit
import SnapKit

class Pay_ReceiptView: BaseView, CustomViewProtocol {
    
    /// 初始化子视图参数
    public func initSetupSubviews()
    {
        addSubview(contentView)
        addSubview(discriptionLabel)
        contentView.addSubview(imgView)
        contentView.addSubview(setBtn)
    }
    
    /// 设置子视图约束
    func makeSubViewConstraints()
    {
        contentView.snp.makeConstraints { (maker) in
            maker.width.equalToSuperview().multipliedBy(345.0/375.0)
            maker.top.equalTo(15)
            maker.centerX.equalToSuperview()
            maker.height.equalTo(contentView.snp.width)
        }
        
        discriptionLabel.snp.makeConstraints { (maker) in
            maker.top.equalTo(contentView.snp.bottom).offset(20)
            maker.left.right.equalToSuperview()
            maker.height.equalTo(20)
        }
        
        imgView.snp.makeConstraints { (maker) in
            maker.height.equalTo(imgView.snp.width)
            maker.width.equalToSuperview().multipliedBy(240.0/345.0)
            maker.centerX.equalToSuperview()
            maker.centerY.equalToSuperview().offset(-4.7)
        }
        setBtn.snp.makeConstraints { (maker) in
            maker.centerX.equalToSuperview()
            maker.height.equalTo(20)
            maker.width.equalTo(62)
            maker.bottom.equalToSuperview().multipliedBy(325.0/345.0)
        }
        
    }
    
    /// 设置视图关联关系
    func setupOutlets(_ owner: CLViewController) {
        let vc = owner as! Pay_ReceiptVC
        vc.discriptionLabel = discriptionLabel
        vc.setBtn = setBtn
        vc.QRcodeImgView = imgView
    }
    
    
    /// 设置事件关联关系
    func setupReceivedActions(_ owner: CLViewController) {
        let vc = owner as! Pay_ReceiptVC
        setBtn.addTarget(vc, action: #selector(Pay_ReceiptVC.tapSetAmountBtn), for: .touchUpInside)
    }
    
    
    // MARK: - Get / Set
    
    private let contentView: ShadowContentView = {
        let view = ShadowContentView()
        view.backgroundColor = UIColor.white
        return view
    }()
    
    private let discriptionLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.appRegularFont(ofPX: 14)
        label.textColor = UIColor.appSubText
        label.textAlignment = .center
        return label
    }()
    
    private let imgView: UIImageView = {
        let imgView = UIImageView()
        imgView.contentMode = .scaleAspectFit
        imgView.backgroundColor = UIColor.clear
        return imgView
    }()
    
    private let setBtn: UIButton = {
        let setBtn = UIButton(type: .custom)
        setBtn.setTitleColor(UIColor.appLinkText, for: .normal)
        setBtn.titleLabel?.font = UIFont.appRegularFont(ofPX: 14)
        return setBtn
    }()
    
}
